<template>
  <div class="app-container">
    <!-- 查询和其他操作 -->
    <div class="filter-container">
      <el-input v-model="listQuery.storeNo" clearable class="filter-item" style="width: 200px;" placeholder="编号" />
      <el-input v-model="listQuery.storeName" clearable class="filter-item" style="width: 200px;" placeholder="名称" />
      <el-button
        v-permission="['promote:accountsreceivable:query']"
        class="filter-item"
        type="primary"
        icon="el-icon-search"
        @click="handleFilter"
      >查找</el-button>
    </div>

    <!-- 查询结果 -->
    <el-table
      v-loading="listLoading"
      :data="list"
      size="small"
      element-loading-text="正在查询中。。。"
      border
      fit
      highlight-current-row
      style="white-space: pre-line"
    >
      <el-table-column prop="storeNo" align="center" label="门店编号"/>
      <el-table-column prop="storeName" align="center" label="门店名称"/>
      <el-table-column prop="contactName" align="center" label="联系人"/>
      <el-table-column prop="contactPhone" align="center" label="联系方式"/>
      <el-table-column prop="allOrderAmount" align="center" label="应收金额">
        <template slot-scope="scope"> {{ (scope.row.allOrderAmount - scope.row.allFinishPaymentAmount).toFixed(2) }}</template>
      </el-table-column>
      <el-table-column align="center" label="类型">
        <template slot-scope="scope">{{ (scope.row.customerType) | filterCustomerType }}</template>
      </el-table-column>
      <el-table-column align="center" label="操作" width="300" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button
            v-permission="['generator:accountsreceivable:query']"
            type="primary"
            size="mini"
            @click="handleDetail(scope.row)"
          >对账</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="listQuery.pageNo"
      :limit.sync="listQuery.limit"
      @pagination="getList"
    />
  </div>
</template>

<style>
.el-table .cell {
  white-space: pre-line;
}
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #20a0ff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 120px;
  height: 120px;
  line-height: 120px;
  text-align: center;
}
.avatar {
  width: 120px;
  height: 120px;
  display: block;
}
</style>

<script>
import { storelist } from '@/api/accountsreceivable'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
export default {
  name: 'AccountsReceivable',
  components: { Pagination },
  filters: {
    filterCustomerType(type) {
      switch (type) {
        case 1 : return '供应商'
        case 2 : return '门店'
        default : return ''
      }
    }
  },
  data() {
    return {
      statusMap: [{ value: 0, name: '禁用' }, { value: 1, name: '正常' }],
      list: undefined,
      total: 0,
      listLoading: true,
      listQuery: {
        pageNo: 1,
        limit: 20,
        status: undefined
      },
      options: [],
      dataForm: {
        id: undefined
      },
      dialogFormVisible: false,
      dialogStatus: '',
      textMap: {
        update: '编辑',
        create: '创建'
      },
      rules: {}
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      storelist(this.listQuery)
        .then(response => {
          response.data.data.items.forEach(item => {
            item.allOrderAmount = item.allOrderAmount / 100
            item.allFinishPaymentAmount = item.allFinishPaymentAmount / 100
          })
          this.list = response.data.data.items
          this.total = response.data.data.total
          this.listLoading = false
        })
        .catch(() => {
          this.list = []
          this.total = 0
          this.listLoading = false
        })
    },
    handleFilter() {
      this.listQuery.pageNo = 1
      this.getList()
    },
    resetForm() {
      this.dataForm = {
        id: undefined
      }
    },
    handleDetail(row) {
      this.$router.push({ path: '/warehouse/accountsreceivable?storeId=' + row.storeId + '&type=' + row.customerType })
    }
  }
}
</script>

